package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.aid.AidDemand;
import com.ruoyi.system.service.aid.IAidDemandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 援助需求Controller
 */
@RestController
@RequestMapping("/aid/demand")
public class AidDemandController extends BaseController {
    @Autowired
    private IAidDemandService aidDemandService;
    /**
     * 获取未满足的需求列表
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:query')")
    @GetMapping("/unfulfilled")
    public AjaxResult getUnfulfilledDemands() {
        AidDemand demand = new AidDemand();
        demand.setStatus("0"); // 状态为未满足的
        List<AidDemand> list = aidDemandService.selectAidDemandList(demand);
        return success(list);
    }
    /**
     * 查询援助需求列表
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:list')")
    @GetMapping("/list")
    public TableDataInfo list(AidDemand aidDemand) {
        startPage();
        List<AidDemand> list = aidDemandService.selectAidDemandList(aidDemand);
        return getDataTable(list);
    }

    /**
     * 导出援助需求列表
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:export')")
    @Log(title = "援助需求", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AidDemand aidDemand) {
        List<AidDemand> list = aidDemandService.selectAidDemandList(aidDemand);
        ExcelUtil<AidDemand> util = new ExcelUtil<AidDemand>(AidDemand.class);
        return util.exportExcel(list, "援助需求数据");
    }

    /**
     * 获取援助需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:query')")
    @GetMapping(value = "/{demandId}")
    public AjaxResult getInfo(@PathVariable("demandId") Long demandId) {
        return success(aidDemandService.selectAidDemandById(demandId));
    }

    /**
     * 新增援助需求
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:add')")
    @Log(title = "援助需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AidDemand aidDemand) {
        return toAjax(aidDemandService.insertAidDemand(aidDemand));
    }

    /**
     * 修改援助需求
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:edit')")
    @Log(title = "援助需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AidDemand aidDemand) {
        return toAjax(aidDemandService.updateAidDemand(aidDemand));
    }

    /**
     * 删除援助需求
     */
    @PreAuthorize("@ss.hasPermi('aid:demand:remove')")
    @Log(title = "援助需求", businessType = BusinessType.DELETE)
    @DeleteMapping("/{demandIds}")
    public AjaxResult remove(@PathVariable Long[] demandIds) {
        return toAjax(aidDemandService.deleteAidDemandByIds(demandIds));
    }
} 